package org.fh.controller.act.editor;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

class Location {
    private double latitude;
    private double longitude;

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }
}

@RestController
public class LocationController {

    @PostMapping("/location")
    public ResponseEntity<Map<String, String>> receiveLocation(@RequestBody Location location) {
        Map<String, String> response = new HashMap<>();
        try {
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            // 这里可以添加更多逻辑，比如存储到数据库等
            System.out.printf("Received location: Latitude %.6f, Longitude %.6f%n", latitude, longitude);
            response.put("message", "Location received successfully");
            return new ResponseEntity<>(response, HttpStatus.OK);
        } catch (Exception e) {
            response.put("error", e.getMessage());
            return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}    